import { get, post } from '@/utils/request';

export interface LoginParams {
    username: string;
    password: string;
}

export interface UserInfo {
    id: number;
    username: string;
    email: string;
    avatar?: string;
}

export const userApi = {
    // 登录
    login(data: LoginParams) {
        return post<{ token: string }>('/auth/login', data);
    },

    // 获取用户信息
    getUserInfo() {
        return get<UserInfo>('/user/info');
    },

    // 登出
    logout() {
        return post('/auth/logout');
    },

    // 修改密码
    changePassword(oldPassword: string, newPassword: string) {
        return post('/user/change-password', { oldPassword, newPassword });
    },
};
